<%--
  Created by IntelliJ IDEA.
  User: ouyongxiong
  Date: 2020/3/16
  Time: 12:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <style>
        .cover {
            position: absolute;
            background-color: rgba(0, 0, 0, 0.4);
            top: 0;
            right: 0;
            left: 0;
            bottom: 0;
            z-index: 998;
        }

        .modal {
            height: 400px;
            width: 600px;
            background-color: white;
            position: absolute;
            top: 50%;
            left: 50%;
            margin-left: -300px;
            margin-top: -200px;
            z-index: 1000;
        }

        .hide {
            display: none;
        }
    </style>
</head>
<script src="/js/jquery.js"></script>
<body>


<div class="cover hide"></div>
<div class="modal hide">
    <form action="/resume/insertOrupdate" method="get">
        <input type="text" id="id" name="id"  hidden="hidden">
        <p>
            <label for="">姓名:
                <input type="text" name="name"  id="name">
            </label>
        </p>
        <p>
            <label for="">地址:
                <input type="text" name="address" id="address">
            </label>
        </p>
        <p>
            <label for="">电话:
                <input type="text" name="phone" id="phone">
            </label>
        </p>
        <p>
            <input type="submit" value="新增/编辑">
            <input id="cancel" type="button" value="取消" onclick="modalCancel()">
        </p>
    </form>
</div>



<div>
    <input type="button" onclick="queryPage()" value="查询">

</div>


<div>
    <input type="button" onclick="updateResume()" value="新增">

</div>

<table border="1" cellpadding="5" cellspacing="0">
    <thead>
    <tr>
        <th>ID</th>
        <th>姓名</th>
        <th>地址</th>
        <th>电话</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody></tbody>

</table>



<script>
    function deleteResume(id) {
        $.ajax({
            url: "/resume/delete?id="+id,
            type: "GET",
            dataType: "json",
            success:function (data) {
                if(data){
                    alert("删除成功！")
                    queryPage();
                }else {
                    alert("删除失败！")
                }
            }
        })
    }

    function updateResume(id) {
        if(id!=null&&id!=''){
            $.ajax({
                url: "/resume/queryOne?id="+id,
                type: "GET",
                dataType: "json",
                success:function (data) {
                    if(data){
                       $("#id").val(data.id);
                        $("#name").val(data.name);
                        $("#address").val(data.address);
                        $("#phone").val(data.phone);
                    }else {
                        alert("查询失败！")
                    }
                }
            })
        }

        //把cover和modal展示出来
        $(".cover").removeClass("hide");
        $(".modal").removeClass("hide");

    }

    function queryPage() {
        $.ajax({
            url: "/resume/page",
            type: "GET",
            dataType: "json",
            success: function(data) {
                var res='';
                for(var i=0;i<data.length;i++){

                    res+='<tr><td>'+data[i].id+'</td><td>'+data[i].name+'</td><td>'+data[i].address+'</td><td>'+data[i].phone+'</td><td><a href="javascript:deleteResume('+data[i].id+');">删除</a> <a href="javascript:updateResume('+data[i].id+');">更新</a> </td></tr>';
                }
                $("tbody").html(res);
            }

        })
    }

    function saveResume() {

    }

    function modalCancel() {
        $(".cover").addClass("hide");
        $(".modal").addClass("hide");
    }

</script>


</body>
</html>
